package com.example.controller;


import com.example.entities.Food;
import com.example.server_engineer.controller.AbstractTypedController;
import com.example.server_engineer.controller.utils.R;
import com.example.service.FoodService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@Tag(name = "食物控制器")
@RequestMapping(value="food")
public class FoodController extends AbstractTypedController<Food,Integer> {

    FoodController(FoodService foodService){
        this.svcContext = foodService;
    }

    @Resource
    FoodService fsrvc;

    @Operation(summary = "按id查找食物")
    @GetMapping("/find/{id}")
    public R getFood(@PathVariable Integer id){
        Food food = fsrvc.getById(id);
        if (food == null) return new R(false, null);
        return new R(true,fsrvc.getById(id)) ;
    }

    @Operation(summary = "查找全部")
    @GetMapping("/query/all")
    public List<Food> queryAll(){
        return fsrvc.queryAll();
    }

    @Operation(summary = "按照商家id查找食物")
    @GetMapping("/query/bybusiness/{id}")
    public R queryByBusinessId(@PathVariable Integer id){
        List<Food> foodlist = fsrvc.queryFoodByBusinessId(id);
        if(foodlist == null){
            return new R(false, null);
        }
        return new R(true,foodlist);
    }

    @Operation(summary = "按照食物名字查找食物")
    @GetMapping("/query/byname/{name}")
    public R queryByName(@PathVariable String name){
        Food food = fsrvc.queryFoodByName(name);
        if (food == null){
            return new R(false, null);
        }
        return new R(true,fsrvc.queryFoodByName(name));
    }

    @Operation(summary = "按照食物名字查商家id")
    @GetMapping("/query/businessid/byname/{name}")
    public R queryBusinessIdByName(@PathVariable String name){
        Integer businessid = fsrvc.findBusinessIdByName(name);
        if(businessid == null){
            return new R(false, null);
        }
        return new R(true,businessid);
    }

    //    @PostMapping("/setImg")
//    @Operation(summary = "插入图片")
//    public String setImgByFoodId(Integer id, MultipartFile file){
//        return fsrvc.setImgByFoodId(id,file);
//    }


//    @GetMapping("/name/{foodid}")
//    public String getFoodName(@PathVariable int foodid ){
//        var food = foodDao.getfoodbyid(foodid);
//        return food.getFoodName();
//    }
//
//    @GetMapping("/explain/{foodid}")
//    public String getFoodExplain(@PathVariable int foodid){
//        var food = foodDao.getfoodbyid(foodid);
//        return food.getFoodExplain();
//    }
//
//    @GetMapping("/price/{foodid}")
//    public int getFoodPrice(@PathVariable int foodid){
//        var food = foodDao.getfoodbyid(foodid);
//        return food.getFoodPrice();
//    }
}
